﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace davejk.Minecraft.ServerWrapper.Utils
{
    public partial class ServerSetup : Form
    {
        public ServerSetup()
        {
            InitializeComponent();

            if (File.Exists(SetupHelper.AppBaseDirectory + "\\Minecraft\\minecraft_server.jar"))
                File.Delete(SetupHelper.AppBaseDirectory + "\\Minecraft\\minecraft_server.jar");

            WebClient DownloadClient = new WebClient();
            DownloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgress);
            DownloadClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadComplete);
            DownloadClient.DownloadFileAsync(new Uri("http://minecraft.net/download/minecraft_server.jar"),
                SetupHelper.AppBaseDirectory + "\\Minecraft\\minecraft_server.jar");
        }

        void DownloadProgress(object sender, DownloadProgressChangedEventArgs e)
        {
            DownloadText.Text = "Downloading Minecraft server...";
            DownloadProgressBar.Style = ProgressBarStyle.Continuous;
            DownloadProgressBar.Value = e.ProgressPercentage;
        }

        void DownloadComplete(object sender, AsyncCompletedEventArgs e)
        {
            this.Close();
        }
    }
}
